//
//  BaseInformationView.m
//  iShanggang
//
//  Created by  bxf on 2017/6/7.
//  Copyright © 2017年 aishanggang. All rights reserved.
//

#import "BaseInformationView.h"
#define cellHeightNumber           80
#import "UIColor+Hex.h"
//#import "UIViewExt.h"
#import "UIView+ZLExtension.h"
@interface BaseInformationView()

@property (nonatomic,weak)UIImageView *iconImageview;
@property (nonatomic,weak)UILabel *nameLabel;;
@property (nonatomic,weak)UILabel *phoneNumberLabel;

@end

@implementation BaseInformationView

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self addContent];
    }
    return self;
}

- (void)addContent {
    
    self.backgroundColor = [UIColor colorWithHex:0xd23023];
    
    UIImageView *iconImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"PC-no-login"]];
    iconImg.zl_x = 20;
    iconImg.zl_size = CGSizeMake(67, 67);
    iconImg.zl_y = cellHeightNumber - 12 - iconImg.zl_height;
    [self addSubview:iconImg];
    iconImg.layer.cornerRadius = 67 / 2.0;
    iconImg.layer.masksToBounds = YES;
    
    UILabel *nameLbl = [self labelTitle:@"登录/注册" size:17];
    [nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImg.mas_right).offset(15);
        make.top.equalTo(iconImg).offset(10);
    }];
    
    UILabel *phoneLbl = [self labelTitle:@"登录后享受更多特权" size:16];
    [phoneLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(nameLbl);
        make.top.equalTo(nameLbl.mas_bottom).offset(4);
    }];
    
    UIImageView *nextImg = [UIImageView new];
    nextImg.image = [UIImage imageNamed:@"profileMessageicon"];
    [self addSubview:nextImg];
    [nextImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.centerY.equalTo(iconImg.mas_centerY);
    }];
    self.iconImageview = iconImg;
    self.nameLabel = nameLbl;
    self.phoneNumberLabel = phoneLbl;
    
    UIButton *touchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    touchBtn.frame = self.frame;
    [touchBtn addTarget:self action:@selector(touchBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:touchBtn];
}

- (UILabel *)labelTitle:(NSString *)title size:(CGFloat)size {
    
    UILabel *label = [UILabel new];
    label.text = title;
    label.font = [UIFont systemFontOfSize:size];
    label.textColor = [UIColor colorWithHex:0xffffff];
    [self addSubview:label];
    
    return label;
}

#pragma mark - set
//- (void)setUserInfo:(ISGUserInfo *)userInfo{
//    _userInfo = userInfo;
//    if ([userInfo isUserAccountEnable]) {
//        //头像
//        if (userInfo.imgResource == nil) {
//            self.iconImageview.image = [UIImage imageNamed:@"PC-no-login"];
//        } else {
//            [self.iconImageview sd_setImageWithURL:[NSURL URLWithString:userInfo.imgResource] placeholderImage:[UIImage imageNamed:@"PC-no-login"]];
//        }
//        if (userInfo.nikeName && userInfo.nikeName.length > 0) {
//            self.nameLabel.text = userInfo.nikeName;
//        } else {
//            self.nameLabel.text = @"您还没设置昵称哦~";
//        }
//        self.phoneNumberLabel.text = userInfo.userPhone;
//    } else {
//        self.iconImageview.image = [UIImage imageNamed:@"PC-no-login"];
//        self.nameLabel.text = @"登录/注册";
//        self.phoneNumberLabel.text = @"登陆后享受更多特权";
//    }
//}

#pragma mark - private action 
- (void)touchBtnAction:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(baseInformationView:didSelectButton:)]) {
        [self.delegate baseInformationView:self didSelectButton:sender];
    }
}


@end
